package com.javaGame.role;

import com.javaGame.frame.MainFrame;
import com.javaGame.role.enemy.EnemyRole;
import com.javaGame.util.ImageChange;

import javax.management.relation.Role;
import java.awt.*;

/**
 * 菱形飞镖类
 */
public class RhombicBullet extends BaseRole{
    /**图片*/
    public static Image[] rhombicImg;
    /**移动方向*/
    private int direction;
    /**右上方向*/
    public static final int RIGHTUP = 0;
    /**右下方向*/
    public static final int RIGHTDOWN = 1;
    /**图片切换对象*/
    private ImageChange imageChange = new ImageChange(3);

    public RhombicBullet(int direction) {
        super(MainFrame.girl.x+10, MainFrame.girl.y+10, 40, 40);
        this.direction = direction;
    }

    @Override
    public void move() {
        this.currentImg = imageChange.change(rhombicImg);
        if(this.direction == RIGHTUP){
            this.x += 15;
            this.y -= 4;
        }
        else if(this.direction == RIGHTDOWN){
            this.x += 15;
            this.y += 4;
        }

        for(int i=0;i<MainFrame.roleList.size();i++){
            BaseRole role = MainFrame.roleList.get(i);
            if(this.rect.intersects(role.rect) && role instanceof EnemyRole){
                EnemyRole enemy = (EnemyRole) role;
                enemy.byHit(50);
                MainFrame.roleList.remove(this);
                MainFrame.roleList.add(new ByHitBom(x,y));
            }
        }
    }
}
